package com.example.a2032.activity;

import android.content.res.Resources;
import android.os.Bundle;
import android.widget.ImageView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.a2032.R;
import com.example.a2032.Utils.Utils;
import com.example.a2032.adapter.SettingAdapter;

import butterknife.BindArray;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SettingActivity extends BaseActivity implements SettingAdapter.onItemClickListener {

    @BindView(R.id.iv_title)
    ImageView ivTitle;
    @BindView(R.id.RecyclerView_Setting)
    RecyclerView RecyclerViewSetting;
    @BindArray(R.array.setting_nameArray)
    String[] settingArray;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        ButterKnife.bind(this);
        init();
    }

    private void init() {

        int[] resIds = Utils.getResourcesImageArray(this, R.array.setting_img_array);
        SettingAdapter settingAdapter = new SettingAdapter(settingArray, resIds);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        RecyclerViewSetting.setLayoutManager(linearLayoutManager);
        RecyclerViewSetting.setAdapter(settingAdapter);
        settingAdapter.setOnItemClickListener(this);
    }

    @OnClick(R.id.iv_title)
    public void onViewClicked() {
        finish();
    }

    public static final String KEY_SettingTitle = "SettingTitle";
    boolean isTurn;

    @Override
    public void onItemClick(String title) {
        Class activity = null;
        Resources resources = getResources();
        //用title不用position
        //位置会根据ui需求更改，且会增加或者删减item,用 position需要相应改代码;
        if (title.equals(resources.getString(R.string.setting_bright))) {
            activity = BrightSettingActivity.class;
        } else if (title.equals(resources.getString(R.string.setting_timeMode))) {
            activity = TimeModeActivity.class;
        } else if (title.equals(resources.getString(R.string.setting_tel))) {
            activity = CallSettingActivity.class;
        } else if (title.equals(resources.getString(R.string.setting_telNotifyMode))) {
            activity = NotifyModeActivity.class;
        } else if (title.equals(resources.getString(R.string.setting_clock))) {
            activity = ClockListActivity.class;
        } else if (title.equals(resources.getString(R.string.setting_voice))) {
            activity = VoiceSettingActivity.class;
        } else if (title.equals(resources.getString(R.string.setting_watchFace))) {
            activity = WatchFaceActivity.class;
        } else if (title.equals(resources.getString(R.string.setting_bindWatch))) {
            activity = BindDeviceActivity.class;
        } else if (title.equals(resources.getString(R.string.setting_reset))) {
            activity = ResetActivity.class;
        } else if (title.equals(resources.getString(R.string.setting_watchInfo))) {
            activity = DeviceInfoActivity.class;
        }else if (title.equals(resources.getString(R.string.setting_tempUnit))) {
            activity = TempUnitSettingActivity.class;
        }else if (title.equals(resources.getString(R.string.setting_language))) {
            activity = LanguageActivity.class;
        }

        startActivity(activity, KEY_SettingTitle, title);
    }


}